import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory;

public class MagazineServer {
	public static void main(String args[]) throws RemoteException,
			MalformedURLException {
		try {
		    java.rmi.registry.LocateRegistry.createRegistry(1099);
		    System.out.println("RMI registry ready.");
		} catch (Exception e) {
		    System.out.println("Exception starting RMI registry:");
		    e.printStackTrace();
		}
		//Per la versione SSL
		System.setProperty("javax.net.ssl.keyStore", "serverkeystore.jks");
		System.setProperty("javax.net.ssl.keyStorePassword", "frafele");
		System.setProperty("javax.net.ssl.trustStore", "servertruststore.jks");
		System.setProperty("javax.net.ssl.trustStorePassword", "frafele");
		
		RMIClientSocketFactory clientFactory=new MagazineClientSSLFactory();
		RMIServerSocketFactory serverFactory=new MagazineServerSSLFactory();
		
		//Istanzio oggetto per connessione non protetta e oggetto
		//per connessione SSL
		Magazine m = new MagazineImpl();
		Naming.rebind("magazine", m);
		Magazine mSSL = new MagazineImpl(clientFactory,serverFactory);
		Naming.rebind("magazineSSL", mSSL);
	}
}
